<?php

namespace App\Http\Controllers;

use App\Models\Logs\ActivityLog;
use App\Traits\ResponseTrait;

class AdminController extends Controller
{
    use ResponseTrait;
    protected const QUERY_LIMIT = 500;
    protected const GUARD_NAME = 'admin';

    protected function guard()
    {
        return auth(self::GUARD_NAME);
    }

    protected function userAllPermissions(): array
    {
        $user = $this->guard()->user();
        return $user ? $user->getAllPermissions()->pluck('name')->toArray() : [];
    }

    protected function createSyslog(?string $desc, $properties, string $logName = 'Syslog'): void
    {
        ActivityLog::createSyslog($desc, $properties, $logName);
    }

    protected function homeMenus(): array
    {
        return  [
            'title' => "主页",
            'icon' => "layui-icon-home",
            'list' => [
                ['title' => "控制台", 'jump' => "/"]
            ]
        ];
    }

    protected function sysPerData($row): array
    {
        return [
            "id" => $row["id"],
            "parent_id" => $row['parent_id'],
            'name' => $row['name'],
            'title' => $row['display_name'],
            'icon' => $row['icon'],
            'jump' => $row['url'],
        ];
    }
}
